﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Modulos/ModuloPrestamo/VistaControl/MasterPagePrestamo.master" AutoEventWireup="true" CodeFile="contratos.aspx.cs" Inherits="Modulos_ModuloPrestamo_VistaControl_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
Módulo de Préstamos - Administrador de Contratos
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <h2>Administrar Contratos</h2><br />
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="CONTRATO_ID" 
        DataSourceID="SqlDataSource1">
        <InsertItemTemplate>
            <table style="width: 100%" frame="box">
                <tr>
                    <td colspan="2">
                        Nuevo contrato</td>
                </tr>
                <tr>
                    <td style="width: 40px">
                        Título:</td>
                    <td>
                        <asp:TextBox ID="TITULO_CONTRATOTextBox" runat="server" 
                            Text='<%# Bind("TITULO_CONTRATO") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                            ControlToValidate="TITULO_CONTRATOTextBox" Display="Dynamic" 
                            ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td style="width: 40px">
                        Uso:</td>
                    <td>
                        <asp:TextBox ID="DES_CONTRATOTextBox" runat="server" 
                            Text='<%# Bind("DES_CONTRATO") %>' />
                    </td>
                </tr>
                <tr>
                    <td style="width: 40px">
                        &nbsp;</td>
                    <td>
                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                        OnClientClick="javascript:if(!confirm('&iquest;Confirma ingresar contrato?'))return false"
                            CommandName="Insert" Text="Insertar" />
                        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                            CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
                    </td>
                </tr>
            </table>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Nuevo contrato" />
            <br />
        </ItemTemplate>
        <EmptyDataTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Crear nuevo contrato" />
        </EmptyDataTemplate>
        </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>"
        DeleteCommand="DELETE FROM [CONTRATO] WHERE [CONTRATO_ID] = @CONTRATO_ID" InsertCommand="INSERT INTO [CONTRATO] ([DES_CONTRATO], [TITULO_CONTRATO]) VALUES (@DES_CONTRATO, @TITULO_CONTRATO)"
        ProviderName="<%$ ConnectionStrings:AppCeiiConnectionString.ProviderName %>"
        
        SelectCommand="SELECT [CONTRATO_ID], [DES_CONTRATO], [TITULO_CONTRATO] FROM [CONTRATO]" 
        UpdateCommand="UPDATE [CONTRATO] SET [DES_CONTRATO] = @DES_CONTRATO, [TITULO_CONTRATO] = @TITULO_CONTRATO WHERE [CONTRATO_ID] = @CONTRATO_ID">
        <DeleteParameters>
            <asp:Parameter Name="CONTRATO_ID" Type="Decimal" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="DES_CONTRATO" Type="String" />
            <asp:Parameter Name="TITULO_CONTRATO" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="DES_CONTRATO" Type="String" />
            <asp:Parameter Name="TITULO_CONTRATO" Type="String" />
            <asp:Parameter Name="CONTRATO_ID" Type="Decimal" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CONTRATO_ID" 
                DataSourceID="SqlDataSource1" 
                EmptyDataText="No hay registros de datos para mostrar.">
                <Columns>
                    <asp:TemplateField ShowHeader="False">
                        <EditItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                            OnClientClick="javascript:if(!confirm('&iquest;Confirma actualizar contrato?'))return false"
                                CommandName="Update" Text="Actualizar"></asp:LinkButton>
                            <br />
                            <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                                CommandName="Cancel" Text="Cancelar"></asp:LinkButton>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                                CommandName="Edit" Text="Editar"></asp:LinkButton>
                            <br /><asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            OnClientClick="javascript:if(!confirm('&iquest;Confirma eliminar contrato?'))return false"
                                CommandName="Delete" Text="Eliminar"></asp:LinkButton><br />
                                <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" 
                                CommandName="Select" Text="Seleccionar"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="CONTRATO_ID" HeaderText="Id" InsertVisible="False" 
                        ReadOnly="True" SortExpression="CONTRATO_ID" />
                    <asp:TemplateField HeaderText="Título" SortExpression="TITULO_CONTRATO">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TITULO_CONTRATO") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                ControlToValidate="TextBox1" Display="Dynamic" 
                                ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("TITULO_CONTRATO") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Uso" SortExpression="DES_CONTRATO">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("DES_CONTRATO") %>' 
                                TextMode="MultiLine"></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("DES_CONTRATO") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
    
    
    <asp:FormView ID="FormView3" runat="server" 
        DataSourceID="SqlDataSourceArtContrato">
        <InsertItemTemplate>
        Agregar artículos a contrato:<br />
            <table style="width: 100%">
                <tr>
                    <td>
                        Contrato:</td>
                    <td>
                        <asp:DropDownList ID="DropDownList1" runat="server" 
                            DataSourceID="SqlDataSource1" DataTextField="TITULO_CONTRATO"
                            SelectedValue='<%# Bind("CONTRATO_ID") %>'
                            DataValueField="CONTRATO_ID">
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td>
                        Artículo:</td>
                    <td>
                        <asp:DropDownList ID="DropDownList2" runat="server" 
                            DataSourceID="SqlDataSource2" DataTextField="TITULO_ARTICULO" 
                            SelectedValue='<%# Bind("ARTICULO_ID") %>'
                            DataValueField="ARTICULO_ID">
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td>
                        Restrcción:</td>
                    <td>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("REST_CUERPO") %>' 
                            TextMode="MultiLine" />
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                    <td>
                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
                            OnClientClick="javascript:if(!confirm('&iquest;Confirma ingresar artículo a contrato?'))return false" 
                            CommandName="Insert" Text="Insertar" />
                        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                            CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
                    </td>
                </tr>
            </table>
        </InsertItemTemplate>
        <ItemTemplate>
            &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Agregar artículos a contrato" />
        </ItemTemplate>
        <EmptyDataTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Agregar artículos a contrato" />
        </EmptyDataTemplate>
    </asp:FormView>
    <asp:GridView ID="GridView3" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" 
        DataKeyNames="CONTRATO_ID,ARTICULO_ID" DataSourceID="SqlDataSourceASDF">
        <Columns>
            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                    OnClientClick="javascript:if(!confirm('&iquest;Confirma eliminar artículo del contrato?'))return false"
                        CommandName="Delete" Text="Eliminar"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="CONTRATO_ID" HeaderText="No.C." 
                InsertVisible="False" ReadOnly="True" SortExpression="CONTRATO_ID" />
            <asp:BoundField DataField="TITULO_CONTRATO" HeaderText="T. Contrato" 
                SortExpression="TITULO_CONTRATO" />
            <asp:BoundField DataField="ARTICULO_ID" HeaderText="No.A." 
                InsertVisible="False" ReadOnly="True" SortExpression="ARTICULO_ID" />
            <asp:BoundField DataField="TITULO_ARTICULO" HeaderText="T. Artículo" 
                SortExpression="TITULO_ARTICULO" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSourceASDF" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
        DeleteCommand="DELETE FROM CUERPO_CONTRATO WHERE (ARTICULO_ID = @ARTICULO_ID) AND (CONTRATO_ID = @CONTRATO_ID)" 
        SelectCommand="SELECT CONTRATO.CONTRATO_ID, CONTRATO.TITULO_CONTRATO, ARTICULO_CONTRATO.ARTICULO_ID, ARTICULO_CONTRATO.TITULO_ARTICULO FROM CUERPO_CONTRATO INNER JOIN ARTICULO_CONTRATO ON CUERPO_CONTRATO.ARTICULO_ID = ARTICULO_CONTRATO.ARTICULO_ID INNER JOIN CONTRATO ON CUERPO_CONTRATO.CONTRATO_ID = CONTRATO.CONTRATO_ID WHERE (CUERPO_CONTRATO.CONTRATO_ID = @id_contrato)">
        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1" Name="id_contrato" 
                PropertyName="SelectedValue" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="ARTICULO_ID" />
            <asp:Parameter Name="CONTRATO_ID" />
        </DeleteParameters>
    </asp:SqlDataSource>
    <br />
    <asp:SqlDataSource ID="SqlDataSourceArtContrato" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
        DeleteCommand="DELETE FROM CUERPO_CONTRATO WHERE (ARTICULO_ID = @id_art) AND (CONTRATO_ID = @id_cont)" 
        InsertCommand="INSERT INTO CUERPO_CONTRATO(ARTICULO_ID, CONTRATO_ID, REST_CUERPO) VALUES (@ARTICULO_ID, @CONTRATO_ID, @REST_CUERPO)" 
        SelectCommand="SELECT CONTRATO.TITULO_CONTRATO, ARTICULO_CONTRATO.TITULO_ARTICULO FROM CONTRATO INNER JOIN CUERPO_CONTRATO ON CONTRATO.CONTRATO_ID = CUERPO_CONTRATO.CONTRATO_ID INNER JOIN ARTICULO_CONTRATO ON CUERPO_CONTRATO.ARTICULO_ID = ARTICULO_CONTRATO.ARTICULO_ID WHERE (CONTRATO.CONTRATO_ID = @id)">
        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1" Name="id" 
                PropertyName="SelectedValue" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="id_art" />
            <asp:Parameter Name="id_cont" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="id_art" />
            <asp:Parameter Name="id_contrato" />
            <asp:Parameter Name="rest" />
        </InsertParameters>
    </asp:SqlDataSource>
    <br /><h2>Administrar Artículos de Contrato</h2><br />
    <asp:FormView ID="FormView2" runat="server" DataKeyNames="ARTICULO_ID" 
        DataSourceID="SqlDataSource2">
        <InsertItemTemplate>
            <table style="width: 100%" frame="box">
                <tr>
                    <td colspan="2">
                        Nuevo artículo</td>
                </tr>
                <tr>
                    <td>
                        Título:</td>
                    <td>
                        <asp:TextBox ID="TITULO_ARTICULOTextBox" runat="server" 
                            Text='<%# Bind("TITULO_ARTICULO") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                            ControlToValidate="TITULO_ARTICULOTextBox" Display="Dynamic" 
                            ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Texto:</td>
                    <td>
                        <asp:TextBox ID="TEXTO_ARTICULOTextBox" runat="server" 
                            Text='<%# Bind("TEXTO_ARTICULO") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                            ControlToValidate="TEXTO_ARTICULOTextBox" Display="Dynamic" 
                            ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                    <td>
                        <asp:LinkButton ID="InsertButton0" runat="server" CausesValidation="True" 
                        OnClientClick="javascript:if(!confirm('&iquest;Confirma ingresar artículo?'))return false"
                            CommandName="Insert" Text="Insertar" />
                        &nbsp;<asp:LinkButton ID="InsertCancelButton0" runat="server" 
                            CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
                    </td>
                </tr>
            </table>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Nuevo artículo" />
            <br />
        </ItemTemplate>
        <EmptyDataTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Crear nuevo contrato" />
        </EmptyDataTemplate>
        </asp:FormView>
    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                DataKeyNames="ARTICULO_ID" DataSourceID="SqlDataSource2" 
                EmptyDataText="No hay registros de datos para mostrar." 
        AllowPaging="True" AllowSorting="True">
                <Columns>
                    <asp:TemplateField ShowHeader="False">
                        <EditItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                            OnClientClick="javascript:if(!confirm('&iquest;Confirma actualizar artículo?'))return false"
                                CommandName="Update" Text="Actualizar"></asp:LinkButton>
                            &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                                CommandName="Cancel" Text="Cancelar"></asp:LinkButton>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                                CommandName="Edit" Text="Editar"></asp:LinkButton>
                            <br />
                            <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            OnClientClick="javascript:if(!confirm('&iquest;Confirma eliminar artículo?'))return false"
                                CommandName="Delete" Text="Eliminar"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="ARTICULO_ID" HeaderText="Id" 
                        ReadOnly="True" SortExpression="ARTICULO_ID" />
                    <asp:TemplateField HeaderText="Título" SortExpression="TITULO_ARTICULO">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TITULO_ARTICULO") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                                ControlToValidate="TextBox1" Display="Dynamic" 
                                ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("TITULO_ARTICULO") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Texto" SortExpression="TEXTO_ARTICULO">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("TEXTO_ARTICULO") %>' 
                                TextMode="MultiLine"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 
                                ControlToValidate="TextBox2" Display="Dynamic" 
                                ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("TEXTO_ARTICULO") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>"
        DeleteCommand="DELETE FROM [ARTICULO_CONTRATO] WHERE [ARTICULO_ID] = @ARTICULO_ID"
        InsertCommand="INSERT INTO [ARTICULO_CONTRATO] ([TITULO_ARTICULO], [TEXTO_ARTICULO]) VALUES (@TITULO_ARTICULO, @TEXTO_ARTICULO)"
        ProviderName="<%$ ConnectionStrings:AppCeiiConnectionString.ProviderName %>"
        SelectCommand="SELECT [ARTICULO_ID], [TITULO_ARTICULO], [TEXTO_ARTICULO] FROM [ARTICULO_CONTRATO]"
        UpdateCommand="UPDATE [ARTICULO_CONTRATO] SET [TITULO_ARTICULO] = @TITULO_ARTICULO, [TEXTO_ARTICULO] = @TEXTO_ARTICULO WHERE [ARTICULO_ID] = @ARTICULO_ID">
        <DeleteParameters>
            <asp:Parameter Name="ARTICULO_ID" Type="Decimal" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="TITULO_ARTICULO" Type="String" />
            <asp:Parameter Name="TEXTO_ARTICULO" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="TITULO_ARTICULO" Type="String" />
            <asp:Parameter Name="TEXTO_ARTICULO" Type="String" />
            <asp:Parameter Name="ARTICULO_ID" Type="Decimal" />
        </UpdateParameters>
    </asp:SqlDataSource>
</asp:Content>

